package com.topnav.mc.admin.entity.wrapper;

import com.topnav.mc.admin.entity.param.DevicePositionParam;
import com.topnav.mc.base.mc.McWrapper;
import org.springframework.util.StringUtils;

public class DevicePositionWrapper extends McWrapper<DevicePositionParam> {
    public DevicePositionWrapper(DevicePositionParam entity) {
        super(entity);
        if (this.permissionGrade != null ){
            if (this.permissionGrade.getPermissionLevel() == 1){
                this.eq("d.user_id",this.permissionGrade.getUserId());
            }else if (this.permissionGrade.getPermissionLevel() == 2){
                this.eq("d.org_id",this.permissionGrade.getOrgId());
            }else if (this.permissionGrade.getPermissionLevel() == 3 || this.permissionGrade.getPermissionLevel() == 4){
                this.likeRight("o.path",this.permissionGrade.getOrgPath());
            }
        }
        if (entity != null){
            if (entity.getId()!=null){this.eq("p.id",entity.getId());}
            if (entity.getBeginTime()!=null){this.ge("p.time",entity.getBeginTime());}
            if (entity.getEndTime()!=null){this.le("p.time",entity.getEndTime());}
            if (!StringUtils.isEmpty(entity.getDeviceCode())){
                this.like("p.device_code", entity.getDeviceCode());
            }
            if (!StringUtils.isEmpty(entity.getChannelCode())){
                this.like("p.channel_code", entity.getChannelCode());
            }
            if (!StringUtils.isEmpty(entity.getDeviceName())){
                this.like("p.device_name", entity.getDeviceName());
            }
            if (entity.getDeviceId()!=null){this.eq("p.device_id",entity.getDeviceId());}

            //this.orderByDesc("p.id");

        }
    }
}
